package com.test07_继承与多态;

/**
 * 继承性
 */
public class YootkDemo_01 {

    public static void main(String[] args) {
        MathBook bookA = new MathBook();
        System.out.println(bookA.getInfo());
        MathBook bookB = new MathBook("线性代数", "高等数学");
        System.out.println(bookB.getInfo());
        MathBook bookC = new MathBook("线性代数", "小陈老师", 58.9, "高等数学");
        System.out.println(bookC.getInfo());
    }
}

/**
 * 图书类
 */
class Book {
    private String title;   // 标题
    private String author;  // 作者
    private double price;   // 价格

    public Book() {
        System.out.println("【Book父类】调用Book类中的无参构造方法。");
    }

    public Book(String title) {
        System.out.println("【Book父类】调用Book类中的单参构造方法。");
        this.title = title;
    }

    public Book(String title, String author, double price) {
        System.out.println("【Book父类】调用Book类中的三参构造方法。");
        this.title = title;
        this.author = author;
        this.price = price;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
}

/**
 * 数学书类
 */
class MathBook extends Book {
    private String type;    // 分类

    public MathBook() {
    }

    public MathBook(String title, String type) {
        super(title);
        this.type = type;
    }

    public MathBook(String title, String author, double price, String type) {
        super(title, author, price);
        this.type = type;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getInfo() {
        return "图书名称：" + this.getTitle() + "、图书作者：" + this.getAuthor() + "、图书价格：" + this.getPrice() + "、学科分类：" + this.getType();
    }
}
